package jogo;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

import javax.swing.JPanel;

public class PanelDamas extends JPanel implements MouseMotionListener,
		MouseListener {

	/**
   * 
   */
	private static final long serialVersionUID = 1L;

	public Damas damas;
	public Colisao colisao;

	boolean highlight11 = false;
	boolean highlight12 = false;
	boolean highlight13 = false;
	boolean highlight14 = false;

	boolean highlight21 = false;
	boolean highlight22 = false;
	boolean highlight23 = false;
	boolean highlight24 = false;

	boolean highlight31 = false;
	boolean highlight32 = false;
	boolean highlight33 = false;
	boolean highlight34 = false;

	boolean highlight41 = false;
	boolean highlight42 = false;
	boolean highlight43 = false;
	boolean highlight44 = false;

	boolean highlight51 = false;
	boolean highlight52 = false;
	boolean highlight53 = false;
	boolean highlight54 = false;

	boolean highlight61 = false;
	boolean highlight62 = false;
	boolean highlight63 = false;
	boolean highlight64 = false;

	boolean highlight71 = false;
	boolean highlight72 = false;
	boolean highlight73 = false;
	boolean highlight74 = false;

	boolean highlight81 = false;
	boolean highlight82 = false;
	boolean highlight83 = false;
	boolean highlight84 = false;

	boolean quadrado11 = false;
	boolean quadrado12 = false;
	boolean quadrado13 = false;
	boolean quadrado14 = false;

	boolean quadrado21 = false;
	boolean quadrado22 = false;
	boolean quadrado23 = false;
	boolean quadrado24 = false;

	boolean quadrado31 = false;
	boolean quadrado32 = false;
	boolean quadrado33 = false;
	boolean quadrado34 = false;

	boolean quadrado61 = false;
	boolean quadrado62 = false;
	boolean quadrado63 = false;
	boolean quadrado64 = false;

	boolean quadrado71 = false;
	boolean quadrado72 = false;
	boolean quadrado73 = false;
	boolean quadrado74 = false;

	boolean quadrado81 = false;
	boolean quadrado82 = false;
	boolean quadrado83 = false;
	boolean quadrado84 = false;

	public boolean moved11 = false;
	public int X11 = 87;
	public int Y11 = 33;
	public int X12 = 246;
	public int Y12 = 33;
	public int X13 = 407;
	public int Y13 = 33;
	public int X14 = 566;
	public int Y14 = 33;

	public int X21 = 6;
	public int Y21 = 110;
	public int X22 = 166;
	public int Y22 = 110;
	public int X23 = 327;
	public int Y23 = 110;
	public int X24 = 487;
	public int Y24 = 110;

	public int X31 = 88;
	public int Y31 = 190;
	public int X32 = 246;
	public int Y32 = 190;
	public int X33 = 407;
	public int Y33 = 190;
	public int X34 = 566;
	public int Y34 = 190;

	public int X41 = 6;
	public int Y41 = 270;
	public int X42 = 166;
	public int Y42 = 270;
	public int X43 = 327;
	public int Y43 = 270;
	public int X44 = 487;
	public int Y44 = 270;

	public int X51 = 6;
	public int Y51 = 350;
	public int X52 = 166;
	public int Y52 = 350;
	public int X53 = 327;
	public int Y53 = 350;
	public int X54 = 487;
	public int Y54 = 350;

	public int X61 = 6;
	public int Y61 = 430;
	public int X62 = 166;
	public int Y62 = 430;
	public int X63 = 327;
	public int Y63 = 430;
	public int X64 = 487;
	public int Y64 = 430;

	public int X71 = 88;
	public int Y71 = 510;
	public int X72 = 246;
	public int Y72 = 510;
	public int X73 = 407;
	public int Y73 = 510;
	public int X74 = 566;
	public int Y74 = 510;

	public int X81 = 6;
	public int Y81 = 590;
	public int X82 = 166;
	public int Y82 = 590;
	public int X83 = 327;
	public int Y83 = 590;
	public int X84 = 487;
	public int Y84 = 590;

	public PanelDamas() {
		damas = new Damas();
		colisao = new Colisao();

		damas.white11X = X11;
		damas.white11Y = Y11;
		colisao.ba11X = X11;
		colisao.ba11Y = Y11;
		damas.white12X = X12;
		damas.white12Y = Y12;
		colisao.ba13X = X12;
		colisao.ba13Y = Y12;
		damas.white13X = X13;
		damas.white13Y = Y13;
		colisao.ba15X = X13;
		colisao.ba15Y = Y13;
		damas.white14X = X14;
		damas.white14Y = Y14;
		colisao.ba17X = X14;
		colisao.ba17Y = Y14;

		damas.white21X = X21;
		damas.white21Y = Y21;
		colisao.ba22X = X21;
		colisao.ba22Y = Y21;
		damas.white22X = X22;
		damas.white22Y = Y22;
		colisao.ba24X = X22;
		colisao.ba24Y = Y22;
		damas.white23X = X23;
		damas.white23Y = Y23;
		colisao.ba26X = X23;
		colisao.ba26Y = Y23;
		damas.white24X = X24;
		damas.white24Y = Y24;
		colisao.ba28X = X24;
		colisao.ba28Y = Y24;

		damas.white31X = X31;
		damas.white31Y = Y31;
		colisao.ba31X = X31;
		colisao.ba31Y = Y31;
		damas.white32X = X32;
		damas.white32Y = Y32;
		colisao.ba33X = X32;
		colisao.ba33Y = Y32;
		damas.white33X = X33;
		damas.white33Y = Y33;
		colisao.ba35X = X33;
		colisao.ba35Y = Y33;
		damas.white34X = X34;
		damas.white34Y = Y34;
		colisao.ba37X = X34;
		colisao.ba37Y = Y34;

		damas.blue11X = X61;
		damas.blue11Y = Y61;
		colisao.ba62X = X61;
		colisao.ba62Y = Y61;
		damas.blue12X = X62;
		damas.blue12Y = Y62;
		colisao.ba64X = X62;
		colisao.ba64Y = Y62;
		damas.blue13X = X63;
		damas.blue13Y = Y63;
		colisao.ba66X = X63;
		colisao.ba66Y = Y63;
		damas.blue14X = X64;
		damas.blue14Y = Y64;
		colisao.ba68X = X64;
		colisao.ba68Y = Y64;

		damas.blue21X = X71;
		damas.blue21Y = Y71;
		colisao.ba71X = X71;
		colisao.ba71Y = Y71;
		damas.blue22X = X72;
		damas.blue22Y = Y72;
		colisao.ba73X = X72;
		colisao.ba73Y = Y72;
		damas.blue23X = X73;
		damas.blue23Y = Y73;
		colisao.ba75X = X73;
		colisao.ba75Y = Y73;
		damas.blue24X = X74;
		damas.blue24Y = Y74;
		colisao.ba77X = X74;
		colisao.ba77Y = Y74;

		damas.blue31X = X81;
		damas.blue31Y = Y81;
		colisao.ba82X = X81;
		colisao.ba82Y = Y81;
		damas.blue32X = X82;
		damas.blue32Y = Y82;
		colisao.ba84X = X82;
		colisao.ba84Y = Y82;
		damas.blue33X = X83;
		damas.blue33Y = Y83;
		colisao.ba86X = X83;
		colisao.ba86Y = Y83;
		damas.blue34X = X84;
		damas.blue34Y = Y84;
		colisao.ba88X = X84;
		colisao.ba88Y = Y84;

		addMouseMotionListener(this);
		addMouseListener(this);
	}

	public void paint(Graphics g) {
		g.setColor(Color.black);
		g.fillRect(0, 0, 660, 700);
		g.setColor(Color.white);
		g.fillRect(660, 0, 700, 700);
		g.setColor(Color.white);

		g.fillRect(2, 26, 80, 80);
		g.fillRect(162, 26, 80, 80);
		g.fillRect(322, 26, 80, 80);
		g.fillRect(482, 26, 80, 80);

		g.fillRect(82, 106, 80, 80);
		g.fillRect(242, 106, 80, 80);
		g.fillRect(402, 106, 80, 80);
		g.fillRect(562, 106, 80, 80);

		g.fillRect(2, 186, 80, 80);
		g.fillRect(162, 186, 80, 80);
		g.fillRect(322, 186, 80, 80);
		g.fillRect(482, 186, 80, 80);

		g.fillRect(82, 266, 80, 80);
		g.fillRect(242, 266, 80, 80);
		g.fillRect(402, 266, 80, 80);
		g.fillRect(562, 266, 80, 80);

		g.fillRect(2, 346, 80, 80);
		g.fillRect(162, 346, 80, 80);
		g.fillRect(322, 346, 80, 80);
		g.fillRect(482, 346, 80, 80);

		g.fillRect(82, 426, 80, 80);
		g.fillRect(242, 426, 80, 80);
		g.fillRect(402, 426, 80, 80);
		g.fillRect(562, 426, 80, 80);

		g.fillRect(2, 506, 80, 80);
		g.fillRect(162, 506, 80, 80);
		g.fillRect(322, 506, 80, 80);
		g.fillRect(482, 506, 80, 80);

		g.fillRect(82, 586, 80, 80);
		g.fillRect(242, 586, 80, 80);
		g.fillRect(402, 586, 80, 80);
		g.fillRect(562, 586, 80, 80);

		// **

		g.setColor(new Color(124, 252, 0));
		damas.checkerWhite11(g);
		damas.checkerWhite12(g);
		damas.checkerWhite13(g);
		damas.checkerWhite14(g);
		damas.checkerWhite21(g);
		damas.checkerWhite22(g);
		damas.checkerWhite23(g);
		damas.checkerWhite24(g);
		damas.checkerWhite31(g);
		damas.checkerWhite32(g);
		damas.checkerWhite33(g);
		damas.checkerWhite34(g);

		g.setColor(new Color(139, 121, 94));
		damas.checkerBlue11(g);
		damas.checkerBlue12(g);
		damas.checkerBlue13(g);
		damas.checkerBlue14(g);
		damas.checkerBlue21(g);
		damas.checkerBlue22(g);
		damas.checkerBlue23(g);
		damas.checkerBlue24(g);
		damas.checkerBlue31(g);
		damas.checkerBlue32(g);
		damas.checkerBlue33(g);
		damas.checkerBlue34(g);

		repaint();
		g.dispose();
		this.setSize(860, 680);
	}

	@Override
	public void mouseDragged(MouseEvent e) {
		if (quadrado11 == true) {
			X11 = e.getX() - 34;
			Y11 = e.getY() - 34;
			colisao.ba11X = X11;
			colisao.ba11Y = Y11;
			damas.white11X = X11;
			damas.white11Y = Y11;
		} else if (quadrado12 == true) {
			X12 = e.getX() - 34;
			Y12 = e.getY() - 34;
			colisao.ba13X = X12;
			colisao.ba13Y = Y12;
			damas.white12X = X12;
			damas.white12Y = Y12;
		} else if (quadrado13 == true) {
			X13 = e.getX() - 34;
			Y13 = e.getY() - 34;
			colisao.ba15X = X13;
			colisao.ba15Y = Y13;
			damas.white13X = X13;
			damas.white13Y = Y13;
		} else if (quadrado14 == true) {
			X14 = e.getX() - 34;
			Y14 = e.getY() - 34;
			colisao.ba17X = X14;
			colisao.ba17Y = Y14;
			damas.white14X = X14;
			damas.white14Y = Y14;
		}

		// **

		else if (quadrado21 == true) {
			X21 = e.getX() - 34;
			Y21 = e.getY() - 34;
			colisao.ba22X = X21;
			colisao.ba22Y = Y21;
			damas.white21X = X21;
			damas.white21Y = Y21;
		} else if (quadrado22 == true) {
			X22 = e.getX() - 34;
			Y22 = e.getY() - 34;
			colisao.ba24X = X22;
			colisao.ba24Y = Y22;
			damas.white22X = X22;
			damas.white22Y = Y22;
		} else if (quadrado23 == true) {
			X23 = e.getX() - 34;
			Y23 = e.getY() - 34;
			colisao.ba26X = X23;
			colisao.ba26Y = Y23;
			damas.white23X = X23;
			damas.white23Y = Y23;
		} else if (quadrado24 == true) {
			X24 = e.getX() - 34;
			Y24 = e.getY() - 34;
			colisao.ba28X = X24;
			colisao.ba28Y = Y24;
			damas.white24X = X24;
			damas.white24Y = Y24;
		}

		// **

		else if (quadrado31 == true) {
			X31 = e.getX() - 34;
			Y31 = e.getY() - 34;
			colisao.ba31X = X31;
			colisao.ba31Y = Y31;
			damas.white31X = X31;
			damas.white31Y = Y31;
		} else if (quadrado32 == true) {
			X32 = e.getX() - 34;
			Y32 = e.getY() - 34;
			colisao.ba33X = X32;
			colisao.ba33Y = Y32;
			damas.white32X = X32;
			damas.white32Y = Y32;
		} else if (quadrado33 == true) {
			X33 = e.getX() - 34;
			Y33 = e.getY() - 34;
			colisao.ba35X = X33;
			colisao.ba35Y = Y33;
			damas.white33X = X33;
			damas.white33Y = Y33;
		} else if (quadrado34 == true) {
			X34 = e.getX() - 34;
			Y34 = e.getY() - 34;
			colisao.ba37X = X34;
			colisao.ba37Y = Y34;
			damas.white34X = X34;
			damas.white34Y = Y34;
		}

		// **

		else if (quadrado61 == true) {
			X61 = e.getX() - 34;
			Y61 = e.getY() - 34;
			colisao.ba62X = X61;
			colisao.ba62Y = Y61;
			damas.blue11X = X61;
			damas.blue11Y = Y61;
		} else if (quadrado62 == true) {
			X62 = e.getX() - 34;
			Y62 = e.getY() - 34;
			colisao.ba64X = X62;
			colisao.ba64Y = Y62;
			damas.blue12X = X62;
			damas.blue12Y = Y62;
		} else if (quadrado63 == true) {
			X63 = e.getX() - 34;
			Y63 = e.getY() - 34;
			colisao.ba66X = X63;
			colisao.ba66Y = Y63;
			damas.blue13X = X63;
			damas.blue13Y = Y63;
		} else if (quadrado64 == true) {
			X64 = e.getX() - 34;
			Y64 = e.getY() - 34;
			colisao.ba68X = X64;
			colisao.ba68Y = Y64;
			damas.blue14X = X64;
			damas.blue14Y = Y64;
		}

		// **

		else if (quadrado71 == true) {
			X71 = e.getX() - 34;
			Y71 = e.getY() - 34;
			colisao.ba71X = X71;
			colisao.ba71Y = Y71;
			damas.blue21X = X71;
			damas.blue21Y = Y71;
		} else if (quadrado72 == true) {
			X72 = e.getX() - 34;
			Y72 = e.getY() - 34;
			colisao.ba73X = X72;
			colisao.ba73Y = Y72;
			damas.blue22X = X72;
			damas.blue22Y = Y72;
		} else if (quadrado73 == true) {
			X73 = e.getX() - 34;
			Y73 = e.getY() - 34;
			colisao.ba75X = X73;
			colisao.ba75Y = Y73;
			damas.blue23X = X73;
			damas.blue23Y = Y73;
		} else if (quadrado74 == true) {
			X74 = e.getX() - 34;
			Y74 = e.getY() - 34;
			colisao.ba77X = X74;
			colisao.ba77Y = Y74;
			damas.blue24X = X74;
			damas.blue24Y = Y74;
		}

		// **

		else if (quadrado81 == true) {
			X81 = e.getX() - 34;
			Y81 = e.getY() - 34;
			colisao.ba82X = X81;
			colisao.ba82Y = Y81;
			damas.blue31X = X81;
			damas.blue31Y = Y81;
		} else if (quadrado82 == true) {
			X82 = e.getX() - 34;
			Y82 = e.getY() - 34;
			colisao.ba84X = X82;
			colisao.ba84Y = Y82;
			damas.blue32X = X82;
			damas.blue32Y = Y82;
		} else if (quadrado83 == true) {
			X83 = e.getX() - 34;
			Y83 = e.getY() - 34;
			colisao.ba86X = X83;
			colisao.ba86Y = Y83;
			damas.blue33X = X83;
			damas.blue33Y = Y83;
		} else if (quadrado84 == true) {
			X84 = e.getX() - 34;
			Y84 = e.getY() - 34;
			colisao.ba88X = X84;
			colisao.ba88Y = Y84;
			damas.blue34X = X84;
			damas.blue34Y = Y84;
		}
	}

	public void mouseMoved(MouseEvent e) {
	}

	public void mouseClicked(MouseEvent e) {
	}

	public void mouseEntered(MouseEvent e) {
	}

	public void mouseExited(MouseEvent e) {
	}

	public void mousePressed(MouseEvent e) {
		if (e.getX() > colisao.ba11X
				&& e.getX() < colisao.ba11X + colisao.ba11.width
				&& e.getY() > colisao.ba11Y
				&& e.getY() < colisao.ba11Y + colisao.ba11.height) {
			quadrado11 = true;
			highlight11 = true;
		}
		else if (e.getX() > colisao.ba13X
				&& e.getX() < colisao.ba13X + colisao.ba13.width
				&& e.getY() > colisao.ba13Y
				&& e.getY() < colisao.ba13Y + colisao.ba13.height) {
			quadrado12 = true;
		}
		else if (e.getX() > colisao.ba15X
				&& e.getX() < colisao.ba15X + colisao.ba15.width
				&& e.getY() > colisao.ba15Y
				&& e.getY() < colisao.ba15Y + colisao.ba15.height) {
			quadrado13 = true;
		}
		else if (e.getX() > colisao.ba17X
				&& e.getX() < colisao.ba17X + colisao.ba17.width
				&& e.getY() > colisao.ba17Y
				&& e.getY() < colisao.ba17Y + colisao.ba17.height) {
			quadrado14 = true;
		}

		// **

		else if (e.getX() > colisao.ba22X
				&& e.getX() < colisao.ba22X + colisao.ba22.width
				&& e.getY() > colisao.ba22Y
				&& e.getY() < colisao.ba22Y + colisao.ba22.height) {
			quadrado21 = true;
		}
		else if (e.getX() > colisao.ba24X
				&& e.getX() < colisao.ba24X + colisao.ba24.width
				&& e.getY() > colisao.ba24Y
				&& e.getY() < colisao.ba24Y + colisao.ba24.height) {
			quadrado22 = true;
		}
		else if (e.getX() > colisao.ba26X
				&& e.getX() < colisao.ba26X + colisao.ba26.width
				&& e.getY() > colisao.ba26Y
				&& e.getY() < colisao.ba26Y + colisao.ba26.height) {
			quadrado23 = true;
		}
		else if (e.getX() > colisao.ba28X
				&& e.getX() < colisao.ba28X + colisao.ba28.width
				&& e.getY() > colisao.ba28Y
				&& e.getY() < colisao.ba28Y + colisao.ba28.height) {
			quadrado24 = true;
		}

		// **

		else if (e.getX() > colisao.ba31X
				&& e.getX() < colisao.ba31X + colisao.ba31.width
				&& e.getY() > colisao.ba31Y
				&& e.getY() < colisao.ba31Y + colisao.ba31.height) {
			quadrado31 = true;
		}
		else if (e.getX() > colisao.ba33X
				&& e.getX() < colisao.ba33X + colisao.ba33.width
				&& e.getY() > colisao.ba33Y
				&& e.getY() < colisao.ba33Y + colisao.ba33.height) {
			quadrado32 = true;
		}
		else if (e.getX() > colisao.ba35X
				&& e.getX() < colisao.ba35X + colisao.ba35.width
				&& e.getY() > colisao.ba35Y
				&& e.getY() < colisao.ba35Y + colisao.ba35.height) {
			quadrado33 = true;
		}
		else if (e.getX() > colisao.ba37X
				&& e.getX() < colisao.ba37X + colisao.ba37.width
				&& e.getY() > colisao.ba37Y
				&& e.getY() < colisao.ba37Y + colisao.ba37.height) {
			quadrado34 = true;
		}

		// **

		else if (e.getX() > colisao.ba71X
				&& e.getX() < colisao.ba71X + colisao.ba72.width
				&& e.getY() > colisao.ba71Y
				&& e.getY() < colisao.ba71Y + colisao.ba72.height) {
			quadrado71 = true;
		}
		else if (e.getX() > colisao.ba73X
				&& e.getX() < colisao.ba73X + colisao.ba74.width
				&& e.getY() > colisao.ba73Y
				&& e.getY() < colisao.ba73Y + colisao.ba74.height) {
			quadrado72 = true;
		}
		else if (e.getX() > colisao.ba75X
				&& e.getX() < colisao.ba75X + colisao.ba76.width
				&& e.getY() > colisao.ba75Y
				&& e.getY() < colisao.ba75Y + colisao.ba76.height) {
			quadrado73 = true;
		}
		else if (e.getX() > colisao.ba77X
				&& e.getX() < colisao.ba77X + colisao.ba78.width
				&& e.getY() > colisao.ba77Y
				&& e.getY() < colisao.ba77Y + colisao.ba78.height) {
			quadrado74 = true;
		}

		// **

		else if (e.getX() > colisao.ba82X
				&& e.getX() < colisao.ba82X + colisao.ba81.width
				&& e.getY() > colisao.ba82Y
				&& e.getY() < colisao.ba82Y + colisao.ba81.height) {
			quadrado81 = true;
		}
		else if (e.getX() > colisao.ba84X
				&& e.getX() < colisao.ba84X + colisao.ba83.width
				&& e.getY() > colisao.ba84Y
				&& e.getY() < colisao.ba84Y + colisao.ba83.height) {
			quadrado82 = true;
		}
		else if (e.getX() > colisao.ba86X
				&& e.getX() < colisao.ba86X + colisao.ba85.width
				&& e.getY() > colisao.ba86Y
				&& e.getY() < colisao.ba86Y + colisao.ba85.height) {
			quadrado83 = true;
		}
		else if (e.getX() > colisao.ba88X
				&& e.getX() < colisao.ba88X + colisao.ba87.width
				&& e.getY() > colisao.ba88Y
				&& e.getY() < colisao.ba88Y + colisao.ba87.height) {
			quadrado84 = true;
		}

		// **

		else if (e.getX() > colisao.ba62X
				&& e.getX() < colisao.ba62X + colisao.ba61.width
				&& e.getY() > colisao.ba62Y
				&& e.getY() < colisao.ba62Y + colisao.ba61.height) {
			quadrado61 = true;
		}
		else if (e.getX() > colisao.ba64X
				&& e.getX() < colisao.ba64X + colisao.ba63.width
				&& e.getY() > colisao.ba64Y
				&& e.getY() < colisao.ba64Y + colisao.ba63.height) {
			quadrado62 = true;
		}
		else if (e.getX() > colisao.ba66X
				&& e.getX() < colisao.ba66X + colisao.ba65.width
				&& e.getY() > colisao.ba66Y
				&& e.getY() < colisao.ba66Y + colisao.ba65.height) {
			quadrado63 = true;
		}
		else if (e.getX() > colisao.ba68X
				&& e.getX() < colisao.ba68X + colisao.ba67.width
				&& e.getY() > colisao.ba68Y
				&& e.getY() < colisao.ba68Y + colisao.ba67.height) {
			quadrado64 = true;
		}
	}

	@Override
	public void mouseReleased(MouseEvent e) {
		highlight11 = false;

		quadrado11 = false;
		quadrado12 = false;
		quadrado13 = false;
		quadrado14 = false;

		quadrado21 = false;
		quadrado22 = false;
		quadrado23 = false;
		quadrado24 = false;

		quadrado31 = false;
		quadrado32 = false;
		quadrado33 = false;
		quadrado34 = false;

		quadrado61 = false;
		quadrado62 = false;
		quadrado63 = false;
		quadrado64 = false;

		quadrado71 = false;
		quadrado72 = false;
		quadrado73 = false;
		quadrado74 = false;

		quadrado81 = false;
		quadrado82 = false;
		quadrado83 = false;
		quadrado84 = false;
	}
}
